//통계메뉴의 왼쪽 세부 메뉴 클릭에 대한 동작
$(document).ready(function(){
	$("#chart1st").hide();
	$("#chart2nd").hide();
	$("#chart3rd").hide();
	$("#statsLeftMenu").on("click",".statsLi",function(){
		var menu=$(this).text();
		if(menu==="주간 불량 추세표"){
			$.ajax({
				type:"POST",
				url:"kimchi.do",
				data:"command=cumulativeFailureCharts",
				dataType:"json",
				success:function(jsonData){
					$(function () {
					    var chart1st;
					    $(document).ready(function() {
					    	var list=jsonData.list;
					    	var date=[];
					    	var count=[];
					    	for(var i=list.length,c=0; c<list.length;c++){
					    		i--;
					    		date[c]=list[i].date;
					    		count[c]=list[i].quantity;
					    	}
					    	chart1st = new Highcharts.Chart({
					            chart: {
					                renderTo: 'chart1st',
					                type: 'line'
					            },
					            title: {
					                text: '주간 불량 추세표'
					            },
					            subtitle: {
					                text: '기준 : 일일 불량 누적 데이터'
					            },
					            xAxis: {
					                categories: date
					            },
					            yAxis: {
					                title: {
					                    text: '불량 횟수'
					                }
					            },
					            tooltip: {
					                enabled: false,
					                formatter: function() {
					                    return '<b>'+ this.series.name +'</b><br/>'+
					                        this.x +': '+ this.y +'회';
					                }
					            },
					            plotOptions: {
					                line: {
					                    dataLabels: {
					                        enabled: true
					                    },
					                    enableMouseTracking: false
					                }
					            },
					            series: [{
					                name: '김치 1 라인',
					                data: count
					            }]
					        });
					    });
					    
					});
				}//success
			});//ajax
			
			$("#chart1st").show();
			$("#chart2nd").hide();
			$("#chart3rd").hide();
		}
		else if(menu==="누적 불량 정보"){
			$.ajax({
				type:"POST",
				url:"kimchi.do",
				data:"command=badDetailChart",
				dataType:"json",
				success:function(jsonData){
					$(function () {
					    var chart;
					    $(document).ready(function() {
					    	var list=jsonData.list;
					    	var hn=[];
					    	var count=[];
					    	for(var i=0; i<list.length;i++){
					    		hn[i]=list[i].hn;
					    		count[i]=list[i].quantity;
					    	}
					        chart = new Highcharts.Chart({
					            chart: {
					                renderTo: 'chart2nd',
					                type: 'column'
					            },
					            title: {
					                text: '누적 불량 정보'
					            },
					            xAxis: {
					                categories: hn
					            },
					            yAxis: {
					                min: 0,
					                title: {
					                    text: '누적 불량'
					                },
					                stackLabels: {
					                    enabled: true,
					                    style: {
					                        fontWeight: 'bold',
					                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
					                    }
					                }
					            },
					            legend: {
					                align: 'right',
					                x: -100,
					                verticalAlign: 'top',
					                y: 20,
					                floating: true,
					                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
					                borderColor: '#CCC',
					                borderWidth: 1,
					                shadow: false
					            },
					            tooltip: {
					                formatter: function() {
					                    return '<b>'+ this.x +'</b><br/>'+
					                        this.series.name +': '+ this.y +'<br/>'+
					                        'Total: '+ this.point.stackTotal;
					                }
					            },
					            plotOptions: {
					                column: {
					                    stacking: 'normal',
					                    dataLabels: {
					                        enabled: true,
					                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
					                    }
					                }
					            },
					            series: [{
					                name: '불량',
					                data: count
					            }]
					        });
					    });
					    
					});
					
				}//success
			});//ajax
			$("#chart2nd").show();
			$("#chart1st").hide();
			$("#chart3rd").hide();
		}
		else if(menu==="주간 생산량"){
			$.ajax({
				type:"POST",
				url:"kimchi.do",
				data:"command=workWeek",
				dataType:"json",
				success:function(jsonData){
					$(function () {
					    var chart3rd;
					    $(document).ready(function() {
					    	var list=jsonData.list;
					    	var date=[];
					    	var count=[];
					    	for(var i=list.length,c=0; c<list.length;c++){
					    		i--;
					    		date[c]=list[i].date;
					    		count[c]=list[i].quantity;
					    	}
					    	chart3rd = new Highcharts.Chart({
					            chart: { 
					                renderTo: 'chart3rd',
					                type: 'line'
					            },
					            title: {
					                text: '주간 작업량'
					            },
					            subtitle: {
					                text: '기준 : 일일 주간 작업량 데이터'
					            },
					            xAxis: {
					                categories: date
					            },
					            yAxis: {
					                title: {
					                    text: '주간 작업량'
					                }
					            },
					            tooltip: {
					                enabled: false,
					                formatter: function() {
					                    return '<b>'+ this.series.name +'</b><br/>'+
					                        this.x +': '+ this.y +'회';
					                }
					            },
					            plotOptions: {
					                line: {
					                    dataLabels: {
					                        enabled: true
					                    },
					                    enableMouseTracking: false
					                }
					            },
					            series: [{
					                name: '일일 주간 작업량',
					                data: count
					            }]
					        });
					    });
					    
					});
				}//success
			});//ajax
			$("#chart3rd").show();
			$("#chart1st").hide();
			$("#chart2nd").hide();
			
		}
		else if(menu==="불량 상세 정보"){
			$("#chart1st").hide();
			$("#chart2nd").hide();
			$("#chart3rd").hide();
			$.ajax({
				type:"POST",
				url:"kimchi.do",
				data:"command=getErrorInfoList",
				dataType:"json",
				success:function(jsonData){
					var tableTr="";
					var data=jsonData.list;
					$.each(data,function(i,value){
						tableTr+="<tr><td>"+value.history_date;
						tableTr+="</td><td>"+value.station_name;
						tableTr+="</td><td>"+value.condition_name;
						tableTr+="</td><td>"+value.inventory_date;
						tableTr+="</td><td>"+value.material_name;
						tableTr+="</td><td>"+value.maker;
						tableTr+="</td></tr>";
					});
					$("#errorinfovotabletr").html(tableTr);
				}
			});
			$("#infoInventoryTableDiv1").css({'visibility': 'visible'});
			$("#errorinfovotable").css({'visibility': 'visible'});
		}
	});
	
});